package pers.cz.javacvdemo.utils;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.IOFileFilter;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;

/**
 * @version 1.0
 * @description:
 * @author: ChengZhi 0336
 * @create: 2025-08-15 17:13
 **/
public class JefFileUtils {

	public static Collection<File> getFilesByPrefix(String directoryPath, String prefix) {
		try {
			File directory = new File(directoryPath);
			// 创建文件名过滤器
			IOFileFilter nameFilter = FileFilterUtils.prefixFileFilter(prefix);
			// 获取所有以指定前缀开头的文件
			Collection<File> files = FileUtils.listFiles(directory, nameFilter, null);
			return files;
		} catch (Exception e) {
			return new ArrayList<>();
		}
	}

}
